package IO3;

import java.io.*;

/**
 * @description: IO_decoration02
 * 字符缓冲流
 * BufferedReader()
 * BufferedWriter()
 * @date: 2019/12/17 19:48
 * @author: Vicuna
 */


public class IO_decoration02 {
    public static void main(String[] args) {
        //1 创建源
        File f = new File("E:/Code/Java练习/IO/src/IO2/aaa.txt");
        File d = new File("E:/Code/Java练习/IO/src/IO2/ccc.txt");
        //2 选择流
        BufferedReader re = null;
        BufferedWriter wr = null;
        try {
            re = new BufferedReader(new FileReader(f));
            wr = new BufferedWriter(new FileWriter(d, false));
            //3 操作（写出）
            String line = null;
            while ((line = re.readLine()) != null) {
                wr.write(line, 0, line.length());
                wr.newLine();                                   //读完一行，切下一行
                // wr.append("A").append("B").append("C");      //可以一直追加
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //4 释放 先打开 后关闭
            if (null != wr) {
                try {
                    wr.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (null != re) {
                try {
                    re.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
